//
//  GXLCircularButton.swift
//  Test_swift
//
//  Created by 李恶魔 on 2020/12/9.
//

import UIKit


/// 圆角 按钮
public class GXLCircularButton: UIButton {

    /*
    // Only override draw() if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    override func draw(_ rect: CGRect) {
        // Drawing code
    }
    */
    
    /// 圆角大小
    public var cornerRadius:CGFloat = 0 {
        didSet {
            self.setNeedsDisplay();
        }
    }
    
    public override func draw(_ rect: CGRect) {
        let path = UIBezierPath.init(roundedRect: rect, byRoundingCorners: [.topLeft,.topRight,.bottomLeft,.bottomRight], cornerRadii: CGSize.init(width: cornerRadius, height: cornerRadius));
        let layer = CAShapeLayer.init();
        layer.backgroundColor = UIColor.clear.cgColor;
        layer.frame = self.bounds;
        layer.path = path.cgPath;
        self.layer.mask = layer;
    }
}
